#pragma once
#ifndef _Screen_H_
#define _Screen_H_
#define MAXSIZE 100
//#define _AFXDLL
#include <iostream>
#include "Point.h"
//#include "afxmt.h"
#include <Windows.h>
#include <mutex>
using namespace std;
class Screen
{
private:
	char points[MAXSIZE][MAXSIZE] = {};
	unsigned width;
	unsigned height;
	mutex mtx;
public:
	Screen(unsigned w, unsigned h) :width(w), height(h) {
		
	}
	Screen(unsigned w, unsigned h, char c) :width(w), height(h)
	{
		for (unsigned i = 0; i<width; ++i)
			for (unsigned j = 0; j<height; ++j)
				points[i][j] = c;
	}
	Screen() = default;
	~Screen();
	inline unsigned get_width() const { return width; }
	inline unsigned get_height() const { return height; }
	Screen* set(Point p);
	Screen* remove(Point p);
	Screen* set(Point p, char c);
	Screen* clear();
	Screen* gameover(unsigned base);
	void display();
};
Screen::~Screen()
{
	
}
void Screen::display()
{
	for (unsigned i = 0; i<width; ++i)
	{
		for (unsigned j = 0; j < height; ++j)
		{
			cout << points[i][j] << flush;
		}
		cout << endl;
	}

}
Screen* Screen::set(Point p)
{
	points[p.X][p.Y] = '#';
	return this;
}
Screen* Screen::set(Point p, char c)
{
	points[p.X][p.Y] = c;
	return this;
}
Screen* Screen::remove(Point p)
{
	points[p.X][p.Y] = ' ';
	return this;
}
Screen* Screen::gameover(unsigned base)
{
	points[width / 2][base] = 'g';
	points[width / 2][base+1] = 'a';
	points[width / 2][base+2] = 'm';
	points[width / 2][base+3] = 'e';
	points[width / 2][base+4] = ' ';
	points[width / 2][base+5] = 'o';
	points[width / 2][base+6] = 'v';
	points[width / 2][base+7] = 'e';
	points[width / 2][base+8] = 'r';
	return this;
}
Screen* Screen::clear()
{
	for (unsigned i = 0; i<width; ++i)
		for (unsigned j = 0; j<height; ++j)
			points[i][j] = ' ';
	return this;
}
#endif